package com.homedo.odin.solution.controller.pc;

import com.homedo.core.common.base.controller.BaseController;
import com.homedo.core.common.base.dto.Meta;
import com.homedo.core.common.base.dto.ResultData;
import com.homedo.core.common.exception.BizException;
import com.homedo.core.common.util.NumberHelper;
import com.homedo.odin.solution.contract.mng.CommonTypeDataResp;
import com.homedo.odin.solution.contract.pc.CommonDataResponseBean;
import com.homedo.odin.solution.service.bizservice.pc.CommonDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: donglibing
 * @date: 2018/3/6 14:39
 * @Description:
 */
@Api(description = "基础数据", tags = {"CommonData"}, produces = MediaType.APPLICATION_JSON_VALUE)
@RestController
@RequestMapping("/common_data")
public class CommonDataController extends BaseController<CommonDataService> {

    @ApiOperation(value = "PC_获取基础数据(根据id获取该id的子孙节点)", httpMethod = "GET")
    @GetMapping
    public ResultData queryChildNodeById(
            @ApiParam(value = "1:企业类型 ,2业务类型,3专业领域,4服务区域,5一级系统属性,6建筑业态,7二级系统属性,8 品牌分类", required = true)
            @RequestParam("id") Integer id) {
        if (!NumberHelper.validate(id)) {
            throw new BizException(Meta.CODE_451.getCode(), "id参数非法");
        }

        List<CommonDataResponseBean> responseBeanList = baseService.queryChildNodeById(id);
        return ResultData.newInstance(Meta.CODE_200, responseBeanList);
    }

    @ApiOperation(value = "PC_根据id获取业态/系统的所有高亮管理",
            notes = "PC_根据id获取业态/系统的所有高亮管理", response = CommonTypeDataResp.class, httpMethod = "GET")
    @GetMapping("/{id}/highlight")
    public ResultData highlight(@ApiParam("1:企业类型 ,2业务类型,3专业领域,4服务区域," +
            "5一级系统属性,6建筑业态,7行业规范分类,8 品牌分类") @PathVariable(value = "id", required = true) Integer id) {
        if (!NumberHelper.validatePositive(id)) {
            throw new BizException(Meta.CODE_451.getCode(), "参数异常");
        }
        CommonTypeDataResp resp = baseService.highlight(id);
        return ResultData.newInstance(Meta.CODE_200, resp);
    }

}
